package com.globalwave.common.datagridrenderer
{
	import com.globalwave.util.CodeUtil;
	import com.globalwave.util.U;
	import com.globalwave.util.XmlUtil;
	
	import mx.controls.Label;
	
	public class CodeLabelRenderer extends Label
	{
		public function CodeLabelRenderer()
		{
			super();
		}
		
		public var valueField:String = "id" ;
		public var labelField:String = "name_" ;
		public var _code:String = null ;
		
		public function set code(value:String):void {
			_code = value ;
		}
		
		override public function set text(value:String):void
		{
		
			try {
				var datas:XML = (CodeUtil.dicts[_code][0] as XML) ;
				
				var entitys:XMLList = datas.HashMap ;
				for (var i:int = 0 ; i < entitys.length() ; i ++) {
					var entity:XML = entitys[i] ; 
					if(U.obj2String(entity[valueField]) == value) {
						super.text = entity[labelField] ;
					    break ;
					}
				}
			} catch (e:Error) {
			    trace (e) ;
				super.text = value ;
			}
			
		}
	}
}